/**
 * [78] 子集
 *
 * 提示：
 * # 1 <= nums.length <= 10
 * # -10 <= nums[i] <= 10
 * # nums 中的所有元素 互不相同
 *
 * @format
 * @lc app=leetcode.cn id=78 lang=javascript
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number[][]}
 */
// 二进制表
var subsets = function (nums) {
    const N = nums.length
    const results = []
    // 每位对应 nums 中元素 1 有 0 无
    let num = ""
    for (let i = 0; i < 2 ** N; i++) {
        // 转二进制
        num = i.toString(2)
        // 补 0
        num = num.padStart(N, 0)
        // console.log(num)
        results.push([])
        for (let j = 0; j < N; j++) if (num[j] == 1) results[i].push(nums[j])
    }
    return results
}
// Accepted
// 10/10 cases passed (56 ms)
// Your runtime beats 96.6 % of javascript submissions
// Your memory usage beats 5.11 % of javascript submissions (53.2 MB)
// debugger
// const nums = [1, 2, 3]
// const results = subsets(nums)
// console.log(results)
// @lc code=end

// var subsets = function (nums) {
//     const result = [[]]
//     // 返回特定长度子集的解集
//     function getSubset(l, i) {

//     }
//     for (let len = 1; len <= nums.length; len++) {
//         let index = 0
//         let subSet = getSubset(len, index)
//         while(subSet){
//             result.push(subSet)
//             subSet = getSubset(len, index)
//         }

//     }
// }
// debugger
// const nums = [1, 2, 3]
// console.log(subsets(nums))
